#region Using Statements
using Microsoft.Xna.Framework;
using PFAGame;
#endregion

namespace PFAGame
{

    class PauseMenuScreen : MenuScreen
    {
        #region Initialization

        public PauseMenuScreen() : base("Paused")
        {
            // Create our menu entries.
            MenuEntry resumeGameMenuEntry = new MenuEntry("Resume Game");
            MenuEntry templateGameMenuEntry = new MenuEntry("Skill tree");
            MenuEntry quitGameMenuEntry = new MenuEntry("Quit Game");
            
            // Hook up menu event handlers.
            resumeGameMenuEntry.Selected += OnCancel;
            templateGameMenuEntry.Selected += templateSelected;
            quitGameMenuEntry.Selected += QuitGameMenuEntrySelected;

            // Add entries to the menu.
            MenuEntries.Add(resumeGameMenuEntry);
            MenuEntries.Add(templateGameMenuEntry);
            MenuEntries.Add(quitGameMenuEntry);
        }

        /// <summary>
        /// overload if the player is dead.
        /// </summary>
        /// <param name="isDead">parameter ignored</param>
        public PauseMenuScreen(bool isDead) : base("You are dead!")
        {
            // Create our menu entries.
            MenuEntry resumeGameMenuEntry = new MenuEntry("Retry");
            MenuEntry templateGameMenuEntry = new MenuEntry("Skill tree");
            MenuEntry quitGameMenuEntry = new MenuEntry("Quit Game");

            // Hook up menu event handlers.
            resumeGameMenuEntry.Selected += OnCancel;
            templateGameMenuEntry.Selected += templateSelected;
            quitGameMenuEntry.Selected += QuitGameMenuEntrySelected;

            // Add entries to the menu.
            MenuEntries.Add(resumeGameMenuEntry);
            MenuEntries.Add(templateGameMenuEntry);
            MenuEntries.Add(quitGameMenuEntry);

            SoundManager.Singleton.PlayMusic(5);
        }

        #endregion

        #region Handle Input

        void QuitGameMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            const string message = "Are you sure you want to quit this game?";

            
            MessageBoxScreen confirmQuitMessageBox = new MessageBoxScreen(message);

            confirmQuitMessageBox.Accepted += ConfirmQuitMessageBoxAccepted;

            ScreenManager.Singleton.AddScreen(confirmQuitMessageBox, ControllingPlayer);
        }

        void templateSelected(object sender, PlayerIndexEventArgs e)
        {
            ScreenManager.Singleton.AddScreen(new TemplateScreen(), e.PlayerIndex);
        }

        void ConfirmQuitMessageBoxAccepted(object sender, PlayerIndexEventArgs e)
        {
            NetworkSessionComponent.LeaveSession(ScreenManager.Singleton, e.PlayerIndex, true);
            LoadingScreen.Load(ScreenManager.Singleton, false, null, new BackgroundScreen(),
                                                                       new MainMenuScreen());
        }


        #endregion
    }
}
